/*
 * @Author: zhouwei wei.zhou@flip.fun
 * @Date: 2024-04-09 20:02:56
 * @LastEditors: zhouwei wei.zhou@flip.fun
 * @LastEditTime: 2024-04-09 20:49:48
 * @FilePath: /50/手撕系列/curry_sum.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
function sum(...arg) {
	let newArgs = [...arg]
	function result(...args) {
		newArgs = newArgs.concat(args)
		return result
	}
	result.value = function () {
		const total = newArgs.reduce((pre, item) => pre + item, 0)
		newArgs = []
		return total
	}
	return result
}

console.log(sum(1, 2).value()) //3
console.log(sum(1, 2)(3, 4).value()) //10
console.log(sum(1)(2)(3)(4).value()) //10
